package com.ruoyi.sales.service.impl;

import java.text.SimpleDateFormat;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sales.mapper.ZcPlanCodeMapper;
import com.ruoyi.sales.domain.ZcPlanCode;
import com.ruoyi.sales.service.IZcPlanCodeService;

/**
 * 计划编码Service业务层处理
 * 
 * @author woo
 * @date 2024-03-22
 */
@Service
public class ZcPlanCodeServiceImpl implements IZcPlanCodeService 
{
    @Autowired
    private ZcPlanCodeMapper zcPlanCodeMapper;

    /**
     * 查询计划编码
     * 
     * @param codeId 计划编码主键
     * @return 计划编码
     */
    @Override
    public ZcPlanCode selectZcPlanCodeByCodeId(Long codeId)
    {

        return zcPlanCodeMapper.selectZcPlanCodeByCodeId(codeId);
    }

    /**
     * 查询计划编码列表
     * 
     * @param zcPlanCode 计划编码
     * @return 计划编码
     */
    @Override
    public List<ZcPlanCode> selectZcPlanCodeList(ZcPlanCode zcPlanCode)
    {
        return zcPlanCodeMapper.selectZcPlanCodeList(zcPlanCode);
    }

    /**
     * 新增计划编码
     * 
     * @param zcPlanCode 计划编码
     * @return 结果
     */
    @Override
    public int insertZcPlanCode(ZcPlanCode zcPlanCode)
    {
        zcPlanCode.setCreateTime(DateUtils.getNowDate());
        //逻辑删除默认存在
        zcPlanCode.setDel(0);

        //计划编码：创建时间年月日时分秒
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String planCode = sdf.format(DateUtils.getNowDate());
        zcPlanCode.setCode(planCode);

        return zcPlanCodeMapper.insertZcPlanCode(zcPlanCode);
    }

    /**
     * 修改计划编码
     * 
     * @param zcPlanCode 计划编码
     * @return 结果
     */
    @Override
    public int updateZcPlanCode(ZcPlanCode zcPlanCode)
    {
        zcPlanCode.setUpdateTime(DateUtils.getNowDate());
        return zcPlanCodeMapper.updateZcPlanCode(zcPlanCode);
    }

    /**
     * 批量删除计划编码
     * 
     * @param codeIds 需要删除的计划编码主键
     * @return 结果
     */
    @Override
    public int deleteZcPlanCodeByCodeIds(Long[] codeIds)
    {
        return zcPlanCodeMapper.deleteZcPlanCodeByCodeIds(codeIds);
    }

    /**
     * 删除计划编码信息
     * 
     * @param codeId 计划编码主键
     * @return 结果
     */
    @Override
    public int deleteZcPlanCodeByCodeId(Long codeId)
    {
        return zcPlanCodeMapper.deleteZcPlanCodeByCodeId(codeId);
    }

    /**
     * 修改计划编码状态
     * @param planCode
     * @return
     */
    @Override
    public int updateCodeStatus(ZcPlanCode planCode) {
        return zcPlanCodeMapper.updateCode(planCode);
    }

    @Override
    public List<ZcPlanCode> selectAllPlanCode() {
        return zcPlanCodeMapper.selectAllPlanCode();
    }
}
